Socket
Socket
Sign inDemoInstall

@thi.ng/equiv

Package Overview
Dependencies
0
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @thi.ng/equiv

Extensible deep value equivalence checking for any data types


Version published
Weekly downloads
114K
increased by1.39%
Maintainers
1
Install size
22.4 kB
Created
Weekly downloads
 

Readme

Source

@thi.ng/equiv

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 192 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Extensible deep value equivalence checking for any data types.

Supports:

  • JS primitives
  • Arrays
  • Plain objects
  • ES6 Sets / Maps
  • Date
  • RegExp
  • Types with IEquiv implementation

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/equiv

ESM import:

import * as equiv from "@thi.ng/equiv";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/equiv"></script>

JSDelivr documentation

For Node.js REPL:

const equiv = await import("@thi.ng/equiv");

Package sizes (brotli'd, pre-treeshake): ESM: 436 bytes

Dependencies

None

API

Generated API docs

import { equiv } from "@thi.ng/equiv";

equiv(
    { a: { b: [1, 2] } },
    { a: { b: [1, 2] } }
);
// true

Implement IEquiv interface

This is useful & required for custom types to take part in equiv checks, by default only plain objects & array are traversed deeply.

Furthermore, by implementing this interface we can better control which internal values / criteria are required to establish equivalence. In this example we exclude the meta property and only check for same type & children equality.

import { IEquiv } from "@thi.ng/api";
import { equiv } from "@thi.ng/equiv";

class Node implements IEquiv {

    meta: any;
    children: any[];

    constructor(children: any[], meta?: any) {
        this.children = children;
        this.meta = meta;
    }

    equiv(o: any) {
        return o instanceof Node && equiv(this.children, o.children);
    }
}

equiv(new Node([1,2,3], "foo"), new Node([1,2,3], "bar"));
// true

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-equiv,
  title = "@thi.ng/equiv",
  author = "Karsten Schmidt",
  note = "https://thi.ng/equiv",
  year = 2016
}

License

© 2016 - 2024 Karsten Schmidt // Apache License 2.0

Keywords

FAQs

Last updated on 08 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc